﻿using Spread.Common.Features.Sample;
using GrapeCity.Spreadsheet;
using GrapeCity.Spreadsheet.Drawing;

namespace Spread.NewShapeEngine.Features
{
  public partial class FlowChart : BaseSampleControl
  {
    public FlowChart()
    {
      InitializeComponent();
      InitializeFlowchart();
    }

    private void InitializeFlowchart()
    {
      fpSpread1.Features.EnhancedShapeEngine = true;
      unchecked
      {
        GrapeCity.Core.SchemeThemeColors blackARGB = GrapeCity.Core.SchemeThemeColors.Text1;
        IWorkbook workbook = fpSpread1.AsWorkbook();
        IWorksheet worksheet = workbook.ActiveSheet;
        IShapes shapes = worksheet.Shapes;
        IShape title = shapes.AddTextEffect(PresetTextEffect.Unspecified, "HOW TO WRITE GOOD CODE:", "Comic Sans MS", 28, true, false, 112, 44);
        title.Fill.Visible = false;
        title.Line.Visible = false;
        title.Width = 610;
        title.Height = 71;
        title.TextFrame.CanEdit = true;
        title.TextFrame.MarginBottom = title.TextFrame.MarginLeft = title.TextFrame.MarginRight = title.TextFrame.MarginTop = 0;
        title.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB;
        IShape start = shapes.AddShape(AutoShapeType.ProcessFlow, 190, 127, 192, 90);
        start.Fill.Visible = false;
        start.Line.ForeColor.ObjectThemeColor = blackARGB;
        start.Line.Weight = 3.0;
        start.TextEffect.Alignment = TextEffectAlignment.Center;
        start.TextEffect.FontName = "Comic Sans MS";
        start.TextEffect.FontSize = 20.0;
        start.TextEffect.Text = "START\nPROJECT.";
        start.TextFrame.CanEdit = true;
        start.TextFrame.MarginBottom = start.TextFrame.MarginLeft = start.TextFrame.MarginRight = start.TextFrame.MarginTop = 0;
        start.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB;
        start.TextFrame.VerticalAnchor = VerticalAnchor.Middle;
        start.TextFrame.WordWrap = true;
        start.PickUp();
        IShape rightOrFast = shapes.AddShape(AutoShapeType.Diamond, 86, 278, 400, 280);
        rightOrFast.Apply();
        rightOrFast.TextEffect.Text = "DO\nTHINGS\nRIGHT OR DO\nTHEM FAST?";
        IShape arrow1 = shapes.AddConnector(ConnectorType.Straight, 0, 0, 10, 10);
        arrow1.Line.ForeColor.ObjectThemeColor = blackARGB;
        arrow1.Line.Weight = 3.0;
        arrow1.Line.EndArrowheadStyle = GrapeCity.Drawing.ArrowheadStyle.Arrow;
        arrow1.ConnectorFormat.BeginConnect(start, 0);
        arrow1.ConnectorFormat.EndConnect(rightOrFast, 0);
        arrow1.RerouteConnections();
        IShape fast = worksheet.Shapes.AddTextEffect(PresetTextEffect.Unspecified, "FAST", "Comic Sans MS", 20, false, false, 488, 375);
        IShape codeFast = shapes.AddShape(AutoShapeType.ProcessFlow, 595, 373, 100, 90);
        codeFast.TextEffect.Text = "CODE\nFAST";
        IShape arrow2 = arrow1.Duplicate();
        arrow2.ConnectorFormat.BeginConnect(rightOrFast, 3);
        arrow2.ConnectorFormat.EndConnect(codeFast, 1);
        IShape doesItWorkYet = shapes.AddShape(AutoShapeType.Diamond, 495, 515, 300, 180);
        doesItWorkYet.TextEffect.Text = "DOES IT\nWORK\nYET?";
        IShape arrow3 = arrow1.Duplicate();
        arrow3.ConnectorFormat.BeginConnect(codeFast, 2);
        arrow3.ConnectorFormat.EndConnect(doesItWorkYet, 0);
        IShape No1 = shapes.AddTextEffect(PresetTextEffect.Unspecified, "NO", "Comic Sans MS", 20, false, false, 795, 565);
        IShape arrow4 = shapes.AddConnector(ConnectorType.Elbow, 0, 0, 100, 100);
        arrow4.Line.ForeColor.ObjectThemeColor = blackARGB;
        arrow4.Line.Weight = 3.0;
        arrow4.Line.EndArrowheadStyle = GrapeCity.Drawing.ArrowheadStyle.Arrow;
        arrow4.ConnectorFormat.BeginConnect(doesItWorkYet, 3);
        arrow4.ConnectorFormat.EndConnect(codeFast, 3);
        arrow4.Adjustments[0] -= 0.75;
        IShape right = shapes.AddTextEffect(PresetTextEffect.Unspecified, "RIGHT", "Comic Sans MS", 20, false, false, 290, 560);
        IShape codeWell = worksheet.Shapes.AddShape(AutoShapeType.ProcessFlow, 232, 628, 106, 90);
        codeWell.TextEffect.Text = "CODE\nWELL";
        IShape arrow5 = arrow1.Duplicate();
        arrow5.ConnectorFormat.BeginConnect(rightOrFast, 2);
        arrow5.ConnectorFormat.EndConnect(codeWell, 0);
        IShape areYouDoneYet = shapes.AddShape(AutoShapeType.Diamond, 105, 783, 360, 200);
        areYouDoneYet.TextEffect.Text = "ARE\nYOU DONE\nYET?";
        IShape arrow6 = arrow1.Duplicate();
        arrow6.ConnectorFormat.BeginConnect(codeWell, 2);
        arrow6.ConnectorFormat.EndConnect(areYouDoneYet, 0);
        IShape No2 = shapes.AddTextEffect(PresetTextEffect.Unspecified, "NO", "Comic Sans MS", 20, false, false, 465, 842);
        IShape arrow7 = arrow4.Duplicate();
        arrow7.ConnectorFormat.BeginConnect(areYouDoneYet, 3);
        arrow7.ConnectorFormat.EndConnect(codeWell, 3);
        arrow7.Adjustments[0] -= 0.75;
        IShape No3 = shapes.AddTextEffect(PresetTextEffect.Unspecified, "NO, AND THE\nREQUIREMENTS\nHAVE CHANGED.", "Comic Sans MS", 20, false, false, 290, 990);
        IShape almostBut = shapes.AddTextEffect(PresetTextEffect.Unspecified, "ALMOST, BUT IT'S\nBECOME A MASS OF\nKLUDGES AND\nSPAGHETTI CODE.", "Comic Sans MS", 20, false, false, 655, 695);
        IShape throwItOut = shapes.AddShape(AutoShapeType.ProcessFlow, 125, 1150, 320, 90);
        throwItOut.TextEffect.Text = "THROW IT ALL OUT\nAND START OVER.";
        IShape arrow8 = arrow1.Duplicate();
        arrow8.ConnectorFormat.BeginConnect(areYouDoneYet, 2);
        arrow8.ConnectorFormat.EndConnect(throwItOut, 0);
        IShape arrow9 = arrow4.Duplicate();
        arrow9.ConnectorFormat.BeginConnect(doesItWorkYet, 2);
        arrow9.ConnectorFormat.EndConnect(throwItOut, 3);
        IShape arrow10 = arrow9.Duplicate();
        arrow10.ConnectorFormat.BeginConnect(throwItOut, 1);
        arrow10.ConnectorFormat.EndConnect(rightOrFast, 1);
        IShape arrow11 = worksheet.Shapes.AddConnector(ConnectorType.Straight, 85, 1195, 125, 1195);
        arrow11.Line.ForeColor.ObjectThemeColor = blackARGB;
        arrow11.Line.Weight = 3.0;
        arrow11.Line.EndArrowheadStyle = GrapeCity.Drawing.ArrowheadStyle.Arrow;
        arrow11.Flip(true);
        IShape cloud = worksheet.Shapes.AddShape(AutoShapeType.Cloud, 720, 950, 80, 80);
        cloud.TextEffect.Text = "?";
        IShape goodCode = shapes.AddShape(AutoShapeType.ProcessFlow, 710, 1070, 100, 100);
        goodCode.TextEffect.Text = "GOOD\nCODE";
        IShape arrow12 = arrow1.Duplicate();
        arrow12.ConnectorFormat.BeginConnect(cloud, 1);
        arrow12.ConnectorFormat.EndConnect(goodCode, 0);
        IShapeRange range1 = shapes.Range(new IShape[] { codeFast, doesItWorkYet, codeWell, areYouDoneYet, throwItOut, cloud, goodCode });
        range1.Line.ForeColor.ObjectThemeColor = blackARGB;
        range1.Line.Weight = 3.0;
        range1.Fill.Visible = false;
        range1.TextEffect.Alignment = TextEffectAlignment.Center;
        range1.TextEffect.FontName = "Comic Sans MS";
        range1.TextEffect.FontSize = 20.0;
        range1.TextFrame.CanEdit = true;
        range1.TextFrame.MarginBottom = range1.TextFrame.MarginLeft = range1.TextFrame.MarginRight = range1.TextFrame.MarginTop = 0;
        range1.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB;
        range1.TextFrame.VerticalAnchor = VerticalAnchor.Middle;
        range1.TextFrame.WordWrap = true;
        IShapeRange range2 = shapes.Range(new IShape[] { fast, No1, right, No2, No3, almostBut });
        range2.Fill.Visible = false;
        range2.Line.Visible = false;
        range2.TextFrame.CanEdit = true;
        range2.TextFrame.MarginBottom = No3.TextFrame.MarginLeft = No3.TextFrame.MarginRight = No3.TextFrame.MarginTop = 0;
        range2.TextFrame.TextRange.Font.Fill.BackColor.ObjectThemeColor = blackARGB;
      }
    }
  }
}

//
//FlowChart.Designer.cs
//

namespace Spread.NewShapeEngine.Features
{
     partial class FlowChart
     {
          /// <summary> 
          /// Required designer variable.
          /// </summary>
          private System.ComponentModel.IContainer components = null;

          /// <summary> 
          /// Clean up any resources being used.
          /// </summary>
          /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
          protected override void Dispose(bool disposing)
          {
               if (disposing && (components != null))
               {
                    components.Dispose();
               }
               base.Dispose(disposing);
          }

          #region Component Designer generated code

          /// <summary> 
          /// Required method for Designer support - do not modify 
          /// the contents of this method with the code editor.
          /// </summary>
          private void InitializeComponent()
          {
               System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FlowChart));
               this.fpSpread1 = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, ((object)(resources.GetObject("pnlMain.Controls"))));
               this.fpSpread1_Sheet1 = this.fpSpread1.GetSheet(0);
               this.pnlMain.SuspendLayout();
               ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).BeginInit();
               this.SuspendLayout();
               // 
               // pnlMain
               // 
               this.pnlMain.Controls.Add(this.fpSpread1);
               this.pnlMain.Size = new System.Drawing.Size(600, 450);
               // 
               // pnlControls
               // 
               this.pnlControls.Size = new System.Drawing.Size(199, 450);
               // 
               // fpSpread1
               // 
               this.fpSpread1.Dock = System.Windows.Forms.DockStyle.Fill;
               this.fpSpread1.Font = new System.Drawing.Font("Calibri", 11F);
               this.fpSpread1.Location = new System.Drawing.Point(0, 0);
               this.fpSpread1.Name = "fpSpread1";
               this.fpSpread1.Size = new System.Drawing.Size(600, 450);
               this.fpSpread1.TabIndex = 0;
               // 
               // FlowChart
               // 
               this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
               this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
               this.Name = "Flow Chart";
               this.Size = new System.Drawing.Size(800, 450);
               this.pnlMain.ResumeLayout(false);
               ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).EndInit();
               this.ResumeLayout(false);

          }

          #endregion

          private FarPoint.Win.Spread.FpSpread fpSpread1;
          private FarPoint.Win.Spread.SheetView fpSpread1_Sheet1;
     }
}
